<!DOCTYPE html>
<html>
	<head>
		<title>基础配置</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<!-- 所有的 css & js 资源 -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.0/lib/theme-chalk/index.css">
		<link rel="stylesheet" href="../../static/sa.css">

		<script src="https://unpkg.com/vue@2.6.10/dist/vue.min.js"></script>
		<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>

		<script src="https://unpkg.com/element-ui@2.13.0/lib/index.js"></script>

		<script src="https://unpkg.com/jquery@3.4.1/dist/jquery.min.js"></script>

		<script src="https://www.layuicdn.com/layer-v3.1.1/layer.js"></script>

		<script src="../../static/sa.js"></script>
		<script src="../../sa-resources/config.js"></script>

		<style type="text/css">
			.demo-table-expand {
				font-size: 0;
			}

			.demo-table-expand label {
				width: 90px;
				color: #99a9bf;
			}

			.demo-table-expand .el-form-item {
				margin-right: 0;
				margin-bottom: 0;
				width: 100%;
				border-bottom: 1px #eeeeee solid;
			}

			.el-table .nomodify-row {
				background: #e2e2e2;
			}
		</style>
	</head>
	<body>
		<div class="vue-box" style="display: none;" :style="'display: block;'">
			<div class="c-panel">
				<!-- ------------- 参数栏 ------------- -->
				<div class="c-title">检索参数</div>
				<el-form>
					<div class="c-item">
						<label class="c-label">类别：</label>
						<el-input size="mini" v-model="queryParams[0].right[0]" placeholder="模糊查询"></el-input>
					</div>

					<div class="c-item">
						<label class="c-label">索引值：</label>
						<el-input size="mini" v-model="queryParams[1].right[0]" placeholder="模糊查询"></el-input>
					</div>

					<div class="c-item" style="min-width: 0px;">
						<el-button size="mini" type="primary" icon="el-icon-search" @click="params.page = 1; f5()">查询</el-button>
					</div>
				</el-form>

				<!-- ------------- 快捷按钮 ------------- -->
				<div class="fast-btn">
					<el-button size="mini" type="primary" icon="el-icon-plus" @click="add()">新增</el-button>
					<!-- <el-button size="mini" type="success" icon="el-icon-view" @click="getBySelect()">查看</el-button> -->
					<el-button size="mini" type="danger" icon="el-icon-delete" @click="deleteByIds()">批量删除</el-button>
					<el-button size="mini" type="warning" icon="el-icon-download" @click="sa.exportExcel('.wuyan-table')">导出</el-button>
					<el-button size="mini" type="info" icon="el-icon-refresh" @click="sa.f5()">重置</el-button>
				</div>

				<!-- ------------- 数据列表 ------------- -->
				<el-table :border="true" :data="dataList" size="small" ref="data-table" class="wuyan-table" row-key="id"
				 :row-class-name="tableRowClassName">
					<el-table-column align="center" type="selection" width="45px"></el-table-column>

					<el-table-column align="center" label="类别" prop="type"></el-table-column>
					<el-table-column align="center" label="索引值" prop="cfgKey"></el-table-column>
					<el-table-column align="center" label="值" prop="cfgValue"></el-table-column>
					<el-table-column align="center" label="备注" prop="remark"></el-table-column>
					<el-table-column align="center" label="创建时间" prop="createTime">
						<template slot-scope="s">
							<span>{{timestampToTime(s.row.createTime)}}</span>
						</template>
					</el-table-column>

					<el-table-column align="center" label="操作" width="240px" fixed="right">
						<template slot-scope="s">
							<el-button class="c-btn" type="success" icon="el-icon-view" @click="get(s.row)">查看</el-button>
							<el-button class="c-btn" type="primary" icon="el-icon-edit" @click="update(s.row)" v-if="s.row.cfgModify === 1">修改</el-button>
							<el-button class="c-btn" type="danger" icon="el-icon-delete" @click="del(s.row)" v-if="s.row.cfgModify === 1">删除</el-button>
						</template>
					</el-table-column>

				</el-table>

				<!-- ------------- 分页 ------------- -->
				<div class="page-box">
					<el-pagination background layout="total, prev, pager, next, sizes, jumper" :current-page.sync="params.page"
					 :page-size.sync="params.limit" :total="dataCount" :page-sizes="[15,30,50,100,500,1000]" @current-change="f5()"
					 @size-change="f5()">
					</el-pagination>
				</div>
			</div>
		</div>

		<script src="../../sa-resources/api.js"></script>
		<script src="../../sa-resources/wuyan.js"></script>
		<script src="../../sa-resources/element-ui-helper.js"></script>
		
		<script>
			var app = new Vue({
				el: '.vue-box',
				data: {
					// 请求参数
					params: {
						isPage: true,
						page: 1,
						limit: 15,
						orders: '[]',
						params: '[]',
					},
					// 查询参数
					queryParams: [{
							left: 'type',
							op: 'like',
							right: ['']
						},
						{
							left: 'cfgKey',
							op: 'like',
							right: ['']
						},
					],
					// 排序参数
					orderParams: [{
							filedName: 'type',
							orderName: 'asc',
						},
						{
							filedName: 'createTime',
							orderName: 'desc',
						},
					],
					// 当前数据
					dataList: [],
					// 数据量
					dataCount: 0,
					// 当前选择条目-单项
					chooseData: {
						row: null,
						field: null,
					},
				},
				created: function() {
					axiosConfig(axios)
					sa.onInputEnter(); // 监听输入框的回车事件，执行查询  
				},
				mounted() {
					this.f5();
				},
				methods: {
					// 刷新
					f5: function() {
						let loading = elLoadding({
							that: this
						})

						this.params.params = queryParamsToJsonStr(this.queryParams)
						this.params.orders = JSON.stringify(this.orderParams)
						axios.get('/wuyan/api/pub-config', {
								params: this.params
							})
							.then(res => {
								this.dataList = res.list ? res.list : []; // 数据

								this.dataCount = res.count; // 分页
								sa.f5TableHeight(); // 刷新表格高度 

								loading.close();
							})
							.catch((err) => { // 请求失败处理
								this.$notify.info({
									title: '消息',
									message: '初始化数据失败'
								});

								loading.close();
							});
					},

					add: function() {
						sa.showIframe('新增数据', 'config-add.html?id=-1', '600px', '500px');
					},

					// 查看
					get: function(data) {
						sa.showIframe('查看数据', 'config-add.html?id=' + data.id + '&show=1', '600px', '500px');
					},

					// 修改
					update: function(data) {
						sa.showIframe('修改数据', 'config-add.html?id=' + data.id, '600px', '500px');
					},

					// 删除
					del: function(data) {
						sa.confirm('是否删除，此操作不可撤销', function() {
							axios.delete('/wuyan/api/pub-config/' + data.id)
								.then(res => {
									sa.arrayDelete(this.dataList, data);
									sa.ok('删除成功');
								})
								.catch(function(err) {
									this.$notify.info({
										title: '消息',
										message: '操作失败'
									});
								});
						}.bind(this));
					},
					// 批量删除
					deleteByIds: function() {
						// 获取选中元素的id列表
						let selection = this.$refs['data-table'].selection;
						let ids = sa.getArrayField(selection, 'id');
						if (selection.length == 0) {
							return sa.msg('请至少选择一条数据')
						}

						// 提交删除 
						sa.confirm('是否删除，此操作不可撤销', function() {
							axios.delete('/wuyan/api/pub-config/' + ids.toString())
								.then(res => {
									sa.arrayDelete(this.dataList, selection);
									sa.ok('删除成功');
								})
								.catch(function(err) { // 请求失败处理
									this.$notify.info({
										title: '消息',
										message: '操作失败'
									});
								});
						}.bind(this));
					},

					// 表格样式控制
					tableRowClassName({
						row,
						rowIndex
					}) {
						if (row.cfgModify !== 1) {
							return 'nomodify-row';
						}

						return '';
					}
				}
			})
		</script>
	</body>
</html>
